﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Hxsoft.AppV1.Module;

namespace Hxsoft.AppV1.Admin.DictionaryManage.Controls
{
	public partial class AddDictionary : BaseUserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				this.DataBind();
				TrDicId.Visible = !IsHiddenControl;				
				TrIndicators.Visible = !IsHiddenControl;
			}
		}	

		private LoadedValue<bool> loadedIsHiddenControl;
		public bool IsHiddenControl
		{
			get {
				if (loadedIsHiddenControl.Loader == null)
					loadedIsHiddenControl.Loader = () => BooleanExtensions.ConvertFromOrDefault(ViewState["IsHiddenControl"], false);
				return loadedIsHiddenControl.Value;
			}
			set {
				if (loadedIsHiddenControl.Setter == null)
					loadedIsHiddenControl.Setter = v => ViewState["IsHiddenControl"] = v;
				loadedIsHiddenControl.Value = value;
			}
		}

		/// <summary>
		/// 属性 DicID
		/// </summary>
		public int DicID
		{
			get
			{
				return Convert.ToInt32(CtrlDicID.Text);
			}
			set
			{
				CtrlDicID.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 Name
		/// </summary>
		public string DicCode
		{
			get
			{
				return Convert.ToString(CtrlDicCode.Text);
			}
			set
			{
				CtrlDicCode.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 Name
		/// </summary>
		public string Name
		{
			get
			{
				return Convert.ToString(CtrlName.Text);
			}
			set
			{
				CtrlName.Text = value.ToString();
			}
		}

		/// <summary>
		/// 属性 Value
		/// </summary>
		public string Value
		{
			get
			{
				if (String.IsNullOrEmpty(CtrlValue.Text))
					return null;

				return Convert.ToString(CtrlValue.Text);
			}
			set
			{
				if (value == null)
					CtrlValue.Text = "";
				else
					CtrlValue.Text = value.ToString();
			}
		}

		public string Indicators
		{
			get
			{
				return CtrlIndicators.Text;
			}
			set
			{
				CtrlIndicators.Text = value;
			}
		}


		/// <summary>
		/// 控件的 DictionaryInfo 实例。
		/// </summary>
		public Dictionary Info
		{
			get
			{
				Dictionary dictionary = new Dictionary();

				dictionary.DicId = DicID;
				dictionary.Name = Name;
				dictionary.DicCode = DicCode;
				dictionary.Value = Value;
				dictionary.Indicators = Indicators;

				return dictionary;
			}
			set
			{
				if (value == null) return;

				DicID = value.DicId;
				Name = value.Name;
				DicCode = value.DicCode;
				Value = value.Value;
				Indicators = value.Indicators;
			}
		}
	}
}